package com.example.demo_springboot.dao;

import com.example.demo_springboot.vo.Account;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AccountMapper {
    //配置使用序列号作为唯一标示示例
    @SelectKey(keyProperty = "id", resultType = Integer.class, before = true, statement = "select pub_seq.nextval from dual")
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into account(id,name, money) values(#{id},#{name}, #{money})")
    int add(@Param("name") String name, @Param("money") double money);

    @SelectKey(keyProperty = "acc.id", resultType = Integer.class, before = true, statement = "select pub_seq.nextval from dual")
    @Options(keyProperty = "acc.id", useGeneratedKeys = true)
    @Insert("insert into account(id,name, money) values(#{acc.id},#{acc.name}, #{acc.money})")
    int addObj(@Param("acc") Account acc);

    @Update("update account set name = #{name}, money = #{money} where id = #{id}")
    int update(@Param("name") String name, @Param("money") double money, @Param("id") int  id);

    int updateByXml(@Param("name") String name, @Param("money") double money, @Param("id") int  id);

    @Delete("delete from account where id = #{id}")
    int delete(int id);

    @Select("select id, name as name, money as money from account where id = #{id}")
    Account findAccount(@Param("id") int id);

    @Select("select id, name as name, money as money from account")
    List<Account> findAccountList();

    Account findUserByName(@Param("name") String name);
}
